/* AnnouncementRepository.java
 *
 * Copyright (C) 2013 Universidad de Sevilla
 * 
 * The use of this project is hereby constrained to the conditions of the 
 * TDG Licence, a copy of which you may download from 
 * http://www.tdg-seville.info/License.html
 * 
 */

package repositories;

import java.util.Collection;
import java.util.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Announcement;
import domain.Customer;

@Repository
public interface AnnouncementRepository extends JpaRepository<Announcement, Integer> {
	
	@Query("select a from Announcement a where ?1 member of a.registrations ")
	Collection<Announcement> findByRegistration(int registrationId);
	
	@Query("select a from Announcement a where a.moment > ?1")
	Collection<Announcement> findAllActive (Date date);
	
	@Query("select a from Announcement a, Registration r where r.owner = ?1 and r.announcement = a ")
	Collection<Announcement> findAllRegister(Customer customer);
	
	
}
